<?php
/**
 * Defines Kodform_Element_Text class
 *
 *
 * @copyright 	Copyright (c) 2006 Boris Tomic (kodmasin.net)
 * @category 	Kodform
 * @package 	Kodform
 * @author 		Boris Tomic
 * @license 	http://boris.kodmasin.net/kodform4:license The BSD License
 *
 */

require_once 'Kodform/Element.php';
require_once 'Kodform/Attributes.php';

/**
 * textarea implementation
 */
class Kodform_Element_Text extends Kodform_Element{
	protected $cols;
	protected $rows;
	/**
	 * creates textarea object
	 * 
	 * @param string $id element id
	 * @param string $displayName display name which will be associed 
	 * with textarea
	 * @param integer $rows defines size of text area. Same as rows in textarea html tag
	 * @param integer $cols defines size of text area. Same as cols in textarea html tag
	 * @param string $defaultValue sets default value 
	 */
	function __construct($id, $displayName, $rows = 0, $cols = 0, $defaultValue = null ){
		parent::__construct($id, $defaultValue);
		self::setDisplayName($displayName);
		$this->cols = $cols;
		$this->rows = $rows;
	}
	/**
	 * display function
	 * 
	 * produces html reprezentation
	 */
	function display(Kodform_Attributes $attributes = null){
		if($attributes == null)
			$attributes = new Kodform_Attributes();
		$attr = $attributes->normal;
		if($this->isRequired())
			$attr = $attributes->required;
		if(!$this->isValid())
			$attr = $attributes->error;
		$str = "<textarea id=\"" . $this->id . "\" name=\"" . $this->id . "\"";
		$str .= $attr->display();
		if($this->cols >0)
			$str .= " cols=\"" . $this->cols . "\"";
		if($this->rows >0)
			$str .= " rows=\"" . $this->rows . "\"";
		$str .= ">" . $this->getValue() . "</textarea>";
		return $str;
	}
	/**
	 * sets how many cols this textarea should have
	 */
	function setCols($cols){
		$this->cols = $cols;
	}
	/**
	 * sets how many rows thia textarea should have
	 */
	function setRows($rows){
		$this->rows = $rows;
	}
}